package top.tagao.features_05_time;

import java.awt.*;
import java.text.SimpleDateFormat;
import java.util.ArrayList;

import java.util.Date;
import java.util.concurrent.*;

/**
 * @author fu-xiao-liu
 * @Date 2022/3/20 21:23
 *   传统的日期格式存在的线程不安全问题
 */
public class Time_01_Problem {

    public static void main(String[] args) throws ExecutionException, InterruptedException {
        SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMdd");

        Callable<Date> task = ()-> sdf.parse("20161218");

        ExecutorService pool = Executors.newFixedThreadPool(10);
        ArrayList<Future<Date>> results = new ArrayList<>();

        for (int i = 0; i < 10; i++) {
            results.add(pool.submit(task));
        }

       for (Future<Date> future : results){
           System.out.println(future.get());
       }

       pool.shutdown();
    }
}
